home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_qt.idb / usr / freeware / include / Qt / qmultilinedit.h.z / qmultilinedit.h
Encoding:
C/C++ Source or Header  |  1998-10-28  |  5.3 KB  |  204 lines

  1. /**********************************************************************
  2. ** $Id: qmultilinedit.h,v 2.38 1998/07/03 00:09:51 hanord Exp $
  3. **
  4. ** Definition of QMultiLineEdit widget class
  5. **
  6. ** Created : 961005
  7. **
  8. ** Copyright (C) 1992-1998 Troll Tech AS.  All rights reserved.
  9. **
  10. ** This file is part of Qt Free Edition, version 1.40.
  11. **
  12. ** See the file LICENSE included in the distribution for the usage
  13. ** and distribution terms, or http://www.troll.no/free-license.html.
  14. **
  15. ** IMPORTANT NOTE: You may NOT copy this file or any part of it into
  16. ** your own programs or libraries.
  17. **
  18. ** Please see http://www.troll.no/pricing.html for information about 
  19. ** Qt Professional Edition, which is this same library but with a
  20. ** license which allows creation of commercial/proprietary software.
  21. **
  22. *****************************************************************************/
  23.  
  24. #ifndef QMULTILINEDIT_H
  25. #define QMULTILINEDIT_H
  26.  
  27. #ifndef QT_H
  28. #include "qtableview.h"
  29. #include "qstring.h"
  30. #include "qlist.h"
  31. #endif // QT_H
  32.  
  33. struct QMultiLineData;
  34.  
  35. class QMultiLineEdit : public QTableView
  36. {
  37.     Q_OBJECT
  38. public:
  39.     QMultiLineEdit( QWidget *parent=0, const char *name=0 );
  40.    ~QMultiLineEdit();
  41.  
  42.     const char *textLine( int line ) const;
  43.     QString text() const;
  44.  
  45.     int numLines() const;
  46.  
  47.     bool    isReadOnly() const;
  48.     bool    isOverwriteMode() const;
  49.  
  50.     void    setFont( const QFont &font );
  51.     virtual void insertLine( const char *s, int line = -1 );
  52.     virtual void insertAt( const char *s, int line, int col );
  53.     virtual void removeLine( int line );
  54.  
  55.     void     cursorPosition( int *line, int *col ) const;
  56.     void    setCursorPosition( int line, int col, bool mark = FALSE );
  57.     void    getCursorPosition( int *line, int *col );
  58.     bool    atBeginning() const;
  59.     bool    atEnd() const;
  60.  
  61.     bool    autoUpdate()    const;
  62.     void    setAutoUpdate( bool );
  63.     
  64.     void    setFixedVisibleLines( int lines );
  65.  
  66. public slots:
  67.     void       clear();
  68.     void       setText( const char * );
  69.     void       append( const char * );
  70.     void       deselect();
  71.     void       selectAll();
  72.     void       setReadOnly( bool );
  73.     void       setOverwriteMode( bool );
  74.     void       paste();
  75.     void       copyText();
  76.     void       cut();
  77.  
  78. signals:
  79.     void    textChanged();
  80.     void    returnPressed();
  81.  
  82. protected:
  83.     void    paintCell( QPainter *, int row, int col );
  84.  
  85.     void    mousePressEvent( QMouseEvent * );
  86.     void    mouseMoveEvent( QMouseEvent * );
  87.     void    mouseReleaseEvent( QMouseEvent * );
  88.     void    mouseDoubleClickEvent( QMouseEvent * );
  89.     void    keyPressEvent( QKeyEvent * );
  90.     void    focusInEvent( QFocusEvent * );
  91.     void    focusOutEvent( QFocusEvent * );
  92.     void    timerEvent( QTimerEvent * );
  93.     void    leaveEvent( QEvent * );
  94.  
  95.     bool    hasMarkedText() const;
  96.     QString    markedText() const;
  97.     int        textWidth( int );
  98.     int        textWidth( QString * );
  99.  
  100.     QPoint    cursorPoint() const;
  101.  
  102. protected:
  103.     virtual void insertChar( char );
  104.     virtual void newLine();
  105.     virtual void killLine();
  106.     virtual void pageUp( bool mark=FALSE );
  107.     virtual void pageDown( bool mark=FALSE );
  108.     virtual void cursorLeft( bool mark=FALSE, bool wrap = TRUE );
  109.     virtual void cursorRight( bool mark=FALSE, bool wrap = TRUE );
  110.     virtual void cursorUp( bool mark=FALSE );
  111.     virtual void cursorDown( bool mark=FALSE );
  112.     virtual void backspace();
  113.     virtual void del();
  114.     virtual void home( bool mark=FALSE );
  115.     virtual void end( bool mark=FALSE );
  116.  
  117.  
  118.     bool    getMarkedRegion( int *line1, int *col1, 
  119.                  int *line2, int *col2 ) const;
  120.     int        lineLength( int row ) const;
  121.     QString    *getString( int row ) const;
  122.  
  123. private slots:
  124.     void    clipboardChanged();
  125.  
  126. private:
  127.     QList<QString> *contents;
  128.     QMultiLineData *mlData;
  129.  
  130.     bool    readOnly;
  131.     bool    cursorOn;
  132.     bool    dummy;
  133.     bool    markIsOn;
  134.     bool    dragScrolling ;
  135.     bool    dragMarking;
  136.     bool    textDirty;    
  137.     bool    wordMark;
  138.     bool    overWrite;
  139.  
  140.     int        cursorX;
  141.     int        cursorY;
  142.     int        markAnchorX;
  143.     int        markAnchorY;
  144.     int        markDragX;
  145.     int        markDragY;
  146.     int        curXPos;    // cell coord of cursor
  147.     int        blinkTimer;
  148.     int        scrollTimer;
  149.  
  150.     int        mapFromView( int xPos, int row );
  151.     int        mapToView( int xIndex, int row );
  152.  
  153.     void    setWidth( int );
  154.     void    updateCellWidth();
  155.     bool     partiallyInvisible( int row );
  156.     void    makeVisible();
  157.     void    setBottomCell( int row );
  158.  
  159.     void     newMark( int posx, int posy, bool copy=TRUE );
  160.     void     markWord( int posx, int posy );
  161.     int     charClass( char );
  162.     void    turnMarkOff();
  163.  
  164. private:    // Disabled copy constructor and operator=
  165.     QMultiLineEdit( const QMultiLineEdit & );
  166.     QMultiLineEdit &operator=( const QMultiLineEdit & );
  167. };
  168.  
  169. inline bool QMultiLineEdit::isReadOnly() const { return readOnly; }
  170.  
  171. inline bool QMultiLineEdit::isOverwriteMode() const { return overWrite; }
  172.  
  173. inline void QMultiLineEdit::setOverwriteMode( bool on ) 
  174.     overWrite = on;
  175.  }
  176.  
  177. inline int QMultiLineEdit::lineLength( int row ) const
  178. {
  179.     return contents->at( row )->length();
  180. }
  181.  
  182. inline bool QMultiLineEdit::atEnd() const 
  183.     return cursorY == (int)contents->count() - 1 
  184.     && cursorX == lineLength( cursorY ) ; 
  185. }
  186.  
  187. inline bool QMultiLineEdit::atBeginning() const 
  188.     return cursorY == 0 && cursorX == 0; 
  189. }
  190.  
  191. inline QString *QMultiLineEdit::getString( int row ) const
  192. {
  193.     return contents->at( row );
  194. }
  195.  
  196. inline int QMultiLineEdit::numLines() const
  197. {
  198.     return contents->count();
  199. }
  200. #endif // QMULTILINED_H
  201.